const router = require('koa-router')()
// 获取我的评论
router.get('/getmycomment',async(ctx,next)=>{
    let openid = ctx.request.query.openid; 
    //获取前端传来的参数openid
    
    let sql="select * from discovery_discuss1 where comment_user_openid=?"
    let reslist = await ctx.db.query(sql,[openid]);
    ctx.body={'code':200,'msg':'ok','commentList':reslist}
})
// 获取我的回复
router.get('/getmyreply',async(ctx,next)=>{
    let openid = ctx.request.query.openid; 
    //获取前端传来的参数openid
    
    let sql="select * from discovery_discuss2 where comment_user_openid=?"
    let reslist = await ctx.db.query(sql,[openid]);
    ctx.body={'code':200,'msg':'ok','replyList':reslist}
})
// 获取评论或回复的动态信息
router.get('/getdis',async(ctx,next)=>{
    let id=ctx.request.query.id
    let sql="select * from updraft where id=?"
    let data =await ctx.db.query(sql,[id]);
    ctx.body={'code':200,'msg':'ok','data':data}
})
// 删除我的回复
router.post('/deletereply',async(ctx,next)=>{
    let id=ctx.request.body.id
   
    let sql="delete  from discovery_discuss2 where comment_id=?"
    let data=await ctx.db.query(sql,[id])
    ctx.body={'code':200,'msg':'ok'}
})
// 删除我的评论
router.post('/deletecomment',async(ctx,next)=>{
    let id=ctx.request.body.id
    let sql="select * from discovery_discuss2 where parent_id=?"
    let data =await  ctx.db.query(sql,[id])
    if(data){
        let sql1="delete from discovery_discuss2 where parent_id=?"
        await ctx.db.query(sql1,[id])
        let sql2="delete from discovery_discuss1 where comment_id=?"
        await ctx.db.query(sql2,[id])
        
    }
    else{
        let sql2="delete from discovery_discuss1 where comment_id=?"
        await ctx.db.query(sql2,[id])
    }
    ctx.body={'code':200,'msg':'ok'}
})
module.exports = router